package com.acwing.lc.part1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author rkc
 * @date 2022/9/5 9:32
 */
public class LC1两数之和 {

    private Map<Integer, Integer> map = new HashMap<>();

    public int[] twoSum(int[] nums, int target) {
        int[] ans = new int[2];
        for (int i = 0; i < nums.length; i++) map.put(nums[i], i);
        for (int i = 0; i < nums.length; i++) {
            Integer res = map.get(target - nums[i]);
            if (res != null && res != i) {
                ans[0] = res;
                ans[1] = i;
                break;
            }
        }
        return ans;
    }
}
